package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 11913
 * @Date 2024/12/15 9:35
 *
 * 护理计划Controller控制层
 */
@Slf4j
@RestController
@RequestMapping("/nursing")
public class NursingPlanController extends BaseController{

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     */
    @GetMapping("/plan")
    public ResponseResult findAll() {
        // 调用业务层,查询所有护理计划
        List<NursingPlan> nursingPlanList = nursingPlanService.findAll();
        // 响应数据
        return ResponseResult.success(nursingPlanList);
    }

    /**
     * 删除护理计划
     * @param id
     * @return
     */
    @ApiOperation("删除护理计划")
    @DeleteMapping("/plan/{id}")
    public ResponseResult deleteById(@PathVariable Long id) {
        logger.info("删除护理计划: {}",id);
        nursingPlanService.deleteById(id);
        return success();
    }

    /**
     * 护理计划条件分页查询
     */
    @GetMapping("/plan/search")
    public ResponseResult<PageResponse<NursingPlanVo>> searchNursingPlan(String name,
                                            Integer status,
                                            @RequestParam (defaultValue = "10") Integer pageSize,
                                            Integer pageNum) {
        // 调用业务层,护理计划条件分页查询
        return ResponseResult.success(nursingPlanService.searchNursingPlan(name, status, pageSize, pageNum));
    }

    /**
     * 新增护理计划
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation("新增护理计划")
    @PostMapping("/plan")
    public ResponseResult save(@RequestBody NursingPlanDto nursingPlanDto) {
        logger.info("新增护理计划: {}",nursingPlanDto);
        nursingPlanService.save(nursingPlanDto);
        return success();
    }

    /**
     * 根据id查询护理计划
     */
    @GetMapping("/plan/{id}")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id) {
        // 调用业务层,根据id查询
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        // 响应数据
        return ResponseResult.success(nursingPlanVo);
    }

    /**
     * 护理计划启用及禁用
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult onOff(@PathVariable Long id,
                                @PathVariable Integer status) {
        // 调用业务层,启用禁用
        nursingPlanService.onOff(id,status);
        // 响应数据
        return ResponseResult.success();
    }


    /**
     * 修改护理计划
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation("修改护理计划")
    @PutMapping("/plan/{id}")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto) {
        logger.info("修改护理计划");
        nursingPlanService.update(nursingPlanDto);
        return success();
    }
}
